function saveWsdl() {
    $("#endpoint-btn").click(function() {
	// set the message
	$("#messageArea").html("server is running, please wait......")

	var sendData = {
	    "endpoint" : $("#endpoint").val()
	};
	$.ajax({
	    url : "../rest/config/endpoint",
	    type : "post",
	    data : sendData,
	    dataType : "text",
	    success : function(data) {
		$("#messageArea").html(data);
		location.reload();
	    },
	    error : function(data) {
		$("#messageArea").html("connect error, status:" + data.status + " ,message:" + data.statusText);

	    }
	});
    });
}

function autoset() {
    
    if ($("#isInitial").val() == "true") {
	$.ajax({
	    url : "../rest/operationMap",
	    dataType : "json",
	}).done(function(data) {
	    
	    var receiveData = data;
	    $("#selectDiv").append("<select id='operationSelect' class='selectpicker form-control'></select>");
	    $.each(data, function(key, value) {
		$("#operationSelect").append("<option value=\"" + key + "\">" + key + "</option>");
	    });
	    $("#operationSelect").change(function() {
		var template = receiveData[$(this).val()];
		$(Result).val(template);
	    });
	    $("#securityCheckDiv").show();
	    $("#templateDiv").show();
	    $("#submitDiv").show();
	    $("#moduleDiv").hide();
	});
    }

}

function sendSoap() {
    $("#sendSoap").click(function() {
	
	var data = $("#Result").val();

	var operationSelect = $("#operationSelect").val();

	$.ajax({
	    url : "../rest/sendSoap",
	    data : {
		"data" : data,
		"operation" : operationSelect,
	    },
	    method : "post",
	    dataType : "text",
	    success : function(data) {
		  
		  $("#response").val(data);

		    $("#responseDiv").show();
	    },
	    error : function(data) {

	    }
	})

    })

}

$(function() {
    saveWsdl();
    autoset();
    sendSoap() ;

})